package com.salton123.camera;

import static android.opengl.GLES20.GL_TRIANGLES;
import static android.opengl.GLES20.glActiveTexture;
import static android.opengl.GLES20.glBindTexture;
import static android.opengl.GLES20.glDrawArrays;
import static android.opengl.GLES20.glGetUniformLocation;
import static android.opengl.GLES20.glUniform1i;

import android.opengl.GLES20;

import com.salton123.camera.BaseRenderer;

import java.nio.ByteBuffer;

public class DirectRenderer extends BaseRenderer {

    protected int uTexPosition = -1;

    @Override
    public void init(){
        super.init();
        uTexPosition = glGetUniformLocation(mShaderProgram, "inputImageTexture");
        mVertexBuffer.clear();
        mVertexBuffer = createBuffer(vertexDataFBO);
    }

    public void doRender(int srcTextureId, int desTextureId, int frameWidth, int frameHeight, float[] srcTransformMatrix, float[] destTransformMatrix, ByteBuffer buffer){
        super.doRender(desTextureId, frameWidth, frameHeight, srcTransformMatrix, destTransformMatrix);

        glActiveTexture(GLES20.GL_TEXTURE0);
        glBindTexture(GLES20.GL_TEXTURE_2D, srcTextureId);
        glUniform1i(uTexPosition, 0);

        glDrawArrays(GL_TRIANGLES, 0, 6);

        saveToBuffer(buffer);
    }
}
